package com.example.assempro

import com.blankj.utilcode.util.AppUtils
import com.example.a_lib.BizApplication
import com.example.a_lib.config.ServerFlavorConfig
import com.example.a_lib.http.HttpSdk
import com.example.a_lib.http.RetrofitFactory
import com.example.a_lib.http.api.ApiVersionInterceptor
import com.example.assempro.api.ApiVersionInterceptor2
import me.jessyan.retrofiturlmanager.RetrofitUrlManager

/**
 * @ClassName: App
 * @Description: java类作用描述
 * @Author: zdl
 * @Date: 2022/3/16 13:49
 */
class App : BizApplication() {

    override fun init() {
        super.init()
        initRetrofitUrlManager()
    }


    /**
     * 动态替换retrofit的BaseUrl
     * @link https://github.com/JessYanCoding/RetrofitUrlManager
     */
    private fun initRetrofitUrlManager() {

        RetrofitUrlManager.getInstance().setDebug(AppUtils.isAppDebug())
        //将每个 BaseUrl 进行初始化,运行时可以随时改变 DOMAIN_NAME 对应的值,从而达到切换 BaseUrl 的效果
        RetrofitUrlManager.getInstance().putDomain(RetrofitFactory.API_HOST_SMART_SITE_NAME, ServerFlavorConfig.API_BASE_URL_IOT_GENERAL.toString() + "/wisdom/app")
        RetrofitUrlManager.getInstance().putDomain(RetrofitFactory.API_HOST_HELMETDOCK_NAME, ServerFlavorConfig.API_BASE_URL_IOT_GENERAL.toString() + "/wisdom/cabinet")
        RetrofitUrlManager.getInstance().putDomain(RetrofitFactory.API_HOST_IOT_SUPERVISE_NAME, ServerFlavorConfig.API_BASE_URL_IOT_GENERAL.toString() + "/wisdom_supervise/app")
        //上述putDomain方法配置的替换规则，只能替换此处传入的BaseUrl，此处传入的BaseURL应该和retrofit初始化的时候传入的BaseUrl相同
        RetrofitUrlManager.getInstance().startAdvancedModel(RetrofitFactory.API_BASE_URL_DEFAULT)

        HttpSdk.addInterceptor(this,ApiVersionInterceptor2())
    }


}